<?php
namespace Admin\Model;
use Think\Model;

class CategoryModel extends Model {

    public function getAll()
    { //获得所有栏目
        return $this->order('cat_order asc')->select();
    }


    public function getTree($id=0){//获得所有子栏目,排好序的[前提是两级]
        $arr = array();
        foreach($this->getAll() as $k=>$v) {
            if ($v['parent_id'] == $id) {
                $v['_cat_name']=$v['cat_name'];
                $arr[] = $v;
            }
            foreach ($this->getAll() as $n => $m) {
                if ($v['cat_id'] == $m['parent_id']) {
                    $m['_cat_name']='﹂'.$m['cat_name'];
                    $arr[] = $m;
                }
            }
        }
        return $arr;
    }

}
